package com.wqc.dynaproxy.jdk;

import com.wqc.dynaproxy.ForumService;
import com.wqc.dynaproxy.ForumServiceImpl;

import java.lang.reflect.Proxy;

// 编写测试类 ForumServiceTest
public class ForumServiceTest {

    public static void main(String[] args) {

        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles","true");


        // 希望被代理的目标业务类
        ForumService target = new ForumServiceImpl();

        // 将目标业务类和横切代码编织到一起
        PerformanceHandler handler = new PerformanceHandler(target);

        // 创建代理类
        ForumService proxy = (ForumService) Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                handler);

        // 调用代理实例
        proxy.removeTopic(1011);
        proxy.updateInfoById(567);
    }
}
